package com.ymt.bpm.web.rest.mobile;

import com.alibaba.fastjson.JSONObject;
import com.ymt.bpm.service.mobile.MFmdService;
import com.ymt.bpm.util.Const;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Johnny on 2017/11/16.
 */
@RequestMapping("/mapi/v1/fmd")
@RestController
public class MFmdResource {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    MFmdService fmds;

    @GetMapping("/formdata/{formid}/{versionid}")
    public JSONObject getFormData(HttpServletRequest req,
                                  @PathVariable("formid")String formid,
                                  @PathVariable("versionid")String versionid) {
        String tenantId = (String)req.getAttribute(Const.TENANT_ID);
        String userId = (String)req.getAttribute(Const.JWT_USER);
        if (log.isDebugEnabled()) {
            log.debug("getFormData tenantId="+tenantId);
            log.debug("getFormData userId="+userId);
            log.debug("getFormData formid="+formid);
            log.debug("getFormData versionid="+versionid);
        }
        return fmds.getFormData(tenantId, formid, versionid);
    }

    @GetMapping("/dict")
    public JSONObject dictTypes(HttpServletRequest req,
                                @RequestParam("types")String typesStr) {
        String lang = Const.LANG_ZH;
        String tenantId = (String)req.getAttribute(Const.TENANT_ID);
        String userId = (String)req.getAttribute(Const.JWT_USER);
        if (log.isDebugEnabled()) {
            log.debug("getFormData tenantId="+tenantId);
            log.debug("getFormData lang="+lang);
            log.debug("getFormData userId="+userId);
            log.debug("getFormData typesStr="+typesStr);
        }
        return fmds.getDictTypes(tenantId, lang, typesStr);
    }

}
